package com.atguigu.gulimallcart.vo;

import java.math.BigDecimal;
import java.util.List;

/**
 * @ClassName Cart
 * @Description TODO
 * @Detail 整个购物车包含购物车的所有商品
 * @Author MyPC
 * @Date 2020/7/13
 * @Version 1.0
 */
public class Cart {
    private List<CartItem> items;
    //商品总数量
    private Integer countNum;
    //商品种类
    private Integer countType;
    //商品总价
    private BigDecimal totalAmount;
    //减免价格，默认是无
    private BigDecimal reducePrice=new BigDecimal("0.00");

    public List<CartItem> getItems() {
        return items;
    }

    public void setItems(List<CartItem> items) {
        this.items = items;
    }

    //商品总数量是动态计算的，不能人为设置
    public Integer getCountNum() {
        int count=0;
        if(this.items !=null && this.items.size()>0){
            for (CartItem item : this.items) {
                count+=item.getCount();
            }
        }
        return count;
    }

    //商品种类数量动态计算的，不能人为设置
    public Integer getCountType() {
        int countType=0;
        if(this.items !=null && this.items.size()>0){
            for (CartItem item : this.items) {
                countType+=1;
            }
        }
        return countType;
    }
    //商品总金额动态计算的，不能人为设置
    public BigDecimal getTotalAmount() {
        //1、计算总价格
        BigDecimal amount=new BigDecimal("0");
        if(this.items !=null && this.items.size()>0){
            for (CartItem item : this.items) {
                if(item.getCheck()){
                    amount=amount.add(item.getTotalPrice());
                }
            }
        }
        //2、减去减免价格
        BigDecimal subtract = amount.subtract(getReducePrice());
        return subtract;
    }

    public BigDecimal getReducePrice() {
        return reducePrice;
    }

    public void setReducePrice(BigDecimal reducePrice) {
        this.reducePrice = reducePrice;
    }

}
